﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EIIS.FrameWork.DomainModel;

namespace EIIS.FrameWork.Repository
{
    /// <summary>
    /// 数据访问接口
    /// </summary>
    public interface IRepository<T> where T:Entity
    {
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        T Get(object id);

        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        T Load(object id);

        /// <summary>
        /// 插入实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>ID</returns>
        object Save(T entity);

        /// <summary>
        /// 修改实体
        /// </summary>
        /// <param name="entity">实体</param>
        void Update(T entity);

        /// <summary>
        /// 修改或保存实体
        /// </summary>
        /// <param name="entity">实体</param>
        void SaveOrUpdate(T entity);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="id">ID</param>
        void Delete(object id);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="idList">ID集合</param>
        void Delete(IList<object> idList);

        /// <summary>
        /// 获取全部集合
        /// </summary>
        /// <returns>集合</returns>
        IQueryable<T> LoadAll();

        /// <summary>
        /// 分页获取全部集合
        /// </summary>
        /// <param name="count">记录总数</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <returns>集合</returns>
        IQueryable<T> LoadAllWithPage(out long count, int pageIndex, int pageSize);

        /// <summary>
        /// 自定义查询(使用HQL)
        /// </summary>
        /// <param name="strQueryString">查询语句</param>
        /// <returns></returns>
        IList<T> Find(string strQueryString);

        /// <summary>
        /// 执行自定义SQL语句(update,delete,insert)
        /// </summary>
        /// <param name="strQueryString">查询语句</param>
        /// <returns></returns>
        object ExecuteSQL(string strQueryString);

        /// <summary>
        /// 执行自定义SQL查询语句语句(select)
        /// </summary>
        /// <param name="strQueryString">查询语句</param>
        /// <returns></returns>
        IList ExecuteSelectSQL(string strQueryString);

        /// <summary>
        /// 执行自定义HQL查询语句语句(select)
        /// </summary>
        /// <param name="strQueryString">查询语句</param>
        /// <returns></returns>
        IList<T> ExecuteHQL(string strQueryString);

        /// <summary>
        /// 判断字段的值是否存在
        /// </summary>
        /// <param name="fieldName">字段名称</param>
        /// <param name="fieldValue">字段值</param>
        /// <param name="id">Id的值，新增为-1，修改为实际值</param>
        /// <param name="where">其他的查询条件</param>
        /// <returns></returns>
        bool IsFieldExist(string fieldName, string fieldValue, string id, string where);
    }
}
